//
//  UISearchBar-Extensions.swift
//
//  Created by zhaosanlong on 2022/5/18.
//

import UIKit

public extension UISearchBar {
    
    func clear() {
        text = ""
    }
    /// Text field inside search bar (if applicable).
    var textField: UITextField? {
        if #available(iOS 13.0, *) {
            return searchTextField
        }
        let subViews = subviews.flatMap(\.subviews)
        guard let textField = (subViews.filter { $0 is UITextField }).first as? UITextField else {
            return nil
        }
        return textField
    }
}
